package edu.nctu.csie.jichang.dp.behavioral;



public class Interpreter {
	public static void main(String[] args) {
		Context ctx = new Context();   
		NonterminalExpression e1 = new NonterminalExpression();
		AbstractExpression e2 = new TerminalExpression();
		e1.successor = e2;
		e1.interpret(ctx);
	}
}
class Context{}
abstract class AbstractExpression {
	abstract void interpret(Context ctx);
}
class TerminalExpression extends AbstractExpression{
	public void interpret(Context ctx) {System.out.println("Terminal");}
}
class NonterminalExpression extends AbstractExpression {
	AbstractExpression successor;
	public void interpret(Context ctx) {
		System.out.println("Nonterminal Start");
		if(successor!=null){successor.interpret(ctx);}
		System.out.println("Nonterminal End");
	}
}